#include <bits/stdc++.h>
using namespace std;

bool check(int n) {
	while (n) {
		if ((n > 9 && n % 10 == 0) || n % 10 == 2 || n % 10 == 1 || n % 10 == 9) {
			return true;
		}
		n /= 10;
	}
	return false;
}

int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i =  1; i <= n; i++) {
		if (check(i))
			sum += i;
	}
	cout << sum ;
	return 0;
}